package com.heima.scan.listener;

import com.heima.model.wemedia.entity.WmNews;
import com.heima.scan.service.WmNewsAutoScanService;
import com.heima.model.constants.KafkaMessageConstants;
import com.heima.wemedia.mapper.WmNewsMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class NewsAutoScanListener {
    @Resource
    private WmNewsAutoScanService wmNewsAutoScanService;

    @Resource
    private WmNewsMapper wmNewsMapper;

    @KafkaListener(topics=KafkaMessageConstants.WM_NEWS_AUTO_SCAN_TOPIC,groupId="WM_NEWS_AUTO_SCAN")
    public void wmNewsAutoScan(ConsumerRecord<String,String>record){
        log.info("接收到自媒体文章自动审核消息,消息内容:{}", record.value());
        String value = record.value();
        WmNews wmNews = wmNewsMapper.selectById(Long.valueOf(value));
        if (wmNews != null) {
            //调用审核业务完成文章审核
            wmNewsAutoScanService.newAutoScan(wmNews);
        }
        log.info("自媒体文章自动审核完成, 文章id:{}", record.value());
    }
}
